package br.com.fromtis.jsf.modal.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import br.com.fromtis.jsf.modal.entity.Cliente;
import br.com.fromtis.jsf.modal.entity.PessoaFisica;
import br.com.fromtis.jsf.util.HibernateUtil;





public class ClienteDao implements IDao<Cliente> , Serializable {
	private static final long serialVersionUID = 1L;
	
	
	private Session session = HibernateUtil.getInstance().getCurrentSession();
	
	@Override
	public void save ( Cliente entity ) {
		Transaction tran = session.beginTransaction();
		session.saveOrUpdate( entity );
		tran.commit();
	}
	
	@Override
	public void delete ( Cliente entity ) {
		Transaction tran = session.beginTransaction();
		session.delete( entity );
		tran.commit();
	}
	
	@Override
	public void merge ( Cliente entity ) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public List<Cliente> getListEntity () {
		return session.createQuery( "from Cliente" ).list();
	}
	
	@Override
	public Cliente getEntity ( Serializable id ) {
		return null;
	}
	
	public List<PessoaFisica> listPessoaFisica () {
		return session.createQuery( "from PessoaFisica" ).list();
	}
	
	public Object findPfById ( Serializable id ) {
		return session.get( PessoaFisica.class, id );
	}
	
	public Object findById ( Class classe, Serializable id ) {
		return session.get( classe, id );
	}
}
